OBJECT Form 99991 UEI - Field Mapping { OBJECT-PROPERTIES { Date=07-03-18; Time=23:11:37; Modified=Yes; Version List=Universal Excel Importer v1.1; } PROPERTIES { Width=10120; Height=10120; CaptionML=[ENU=Field Mapping; PLK=Ustawienie mapowania p¢l]; Minimizable=No; Maximizable=No; MultipleNewLines=No; InsertAllowed=No; DeleteAllowed=No; TableBoxID=1000000000; SourceTable=Table370; DataCaptionExpr=mapDescriptor; OnInit=BEGIN FILTERGROUP(8); SETRANGE("Row No.", UEICode.FieldMappingMinRange,UEICode.FieldMappingMaxRange); FILTERGROUP(0); //HideUnchangeable := TRUE; calcOptions; // TableNo := 60037; END; OnOpenForm=BEGIN enableConstFieldsView; enableOptions; // CurrForm.doInsert.VISIBLE(FALSE); CurrForm.DoValidate.ENABLED(NOT oDontChangeValidation); CurrForm.fFieldValidate.ENABLED(NOT oDontChangeValidation); CurrForm.doImport.ENABLED(NOT oDontChangeMapping); CurrForm.MapToField.ENABLED(NOT oDontChangeMapping); IF FIND('-') THEN; END; } CONTROLS { { 1000000003;CommandButton;5170;9350;2200;550; HorzGlue=Right; VertGlue=Bottom; Default=Yes; PushAction=LookupOK; InvalidActionAppearance=Hide } { 1000000004;CommandButton;7590;9350;2200;550; HorzGlue=Right; VertGlue=Bottom; Cancel=Yes; PushAction=LookupCancel; InvalidActionAppearance=Hide } { 1000000000;TableBox;110 ;110 ;9790 ;7260 ;HorzGlue=Both; VertGlue=Both; HeadingHeight=880; InlineEditing=No } { 1000000001;TextBox;0 ;1210 ;3300 ;440 ;HorzGlue=Both; Editable=No; ParentControl=1000000000; InColumn=Yes; SourceExpr="Cell Value as Text"; OnFormat=BEGIN CASE TRUE OF Formula2 <>'' : CurrForm."Cell Value as Text".UPDATEFONTBOLD(TRUE); NumberFormat='': CurrForm."Cell Value as Text".UPDATEFORECOLOR := 255+(192*255)+(192*255*255); END; END; } { 1000000002;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000001; InColumnHeading=Yes; CaptionML=[ENU=Excel header column; PLK=Pola nagˆowka w Excelu] } { 1000000005;TextBox;3307 ;330 ;2540 ;440 ;Name=MapToField; Editable=Yes; ParentControl=1000000000; InColumn=Yes; CaptionML=[ENU=Map to; PLK=Mapuj do]; SourceExpr=Formula; OnFormat=BEGIN CASE TRUE OF ((Formula2 <>'') AND NOT Underline) OR ((Formula2 <>'') AND ("Cell Value as Text" ='') AND (Formula3= '')) : CurrForm.MapToField.UPDATEFORECOLOR := 255; NumberFormat = '' : CurrForm.MapToField.UPDATEFORECOLOR := 255+(192*255)+(192*255*255); END; IF Formula2 <>'' THEN CurrForm.MapToField.UPDATEFONTBOLD(TRUE); END; OnValidate=VAR i@1000000001 : Integer; OtherMapSoure@1000000002 : Text[50]; BEGIN IF Formula = '' THEN BEGIN IF (Formula2 <>'') AND (ActiveMappingExists(Comment,FALSE,Rec) = '') THEN ERROR(''); cleanMappingInfo(Rec); EXIT; END; IF EVALUATE(i,Formula) THEN Field.GET(TableNo,i) ELSE FindFieldByName(Field,TableNo,Formula); OtherMapSoure := ActiveMappingExists(FORMAT(Field."No.",0,2),TRUE,Rec); IF OtherMapSoure <> '' THEN ERROR(Text004, Field.FieldName, OtherMapSoure); fillMappingInfo(Rec,Field); END; OnLookup=VAR FName@1000000003 : Text[50]; fno@1000000002 : Integer; OtherMapSoure@1000000004 : Text[50]; BEGIN fno := TargetFieldLookup(FName) ; IF fno >0 THEN BEGIN OtherMapSoure := ActiveMappingExists(FORMAT(fno,0,2),TRUE,Rec); IF OtherMapSoure <> '' THEN BEGIN ERROR(Text004,Formula,OtherMapSoure); END; Field.GET(TableNo,fno); fillMappingInfo(Rec,Field); END; END; OnAfterValidate=BEGIN //CurrForm.UPDATE(false); END; } { 1000000006;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000005; InColumnHeading=Yes } { 1000000007;CheckBox;6710;1210 ;1100 ;440 ;Name=doImport; ParentControl=1000000000; InColumn=Yes; ShowCaption=No; CaptionML=[ENU=Import; PLK=Importuj]; SourceExpr=Underline; OnValidate=VAR OtherMapSoure@1000000001 : Text[50]; MapTo@1000000002 : Integer; BEGIN IF Underline THEN BEGIN OtherMapSoure := ActiveMappingExists(Comment,TRUE,Rec); IF OtherMapSoure <> '' THEN ERROR(Text004,Formula,OtherMapSoure); END; CASE TRUE OF NumberFormat='': Underline := FALSE; // non importable field Formula ='': Underline := FALSE; // no mapping exist END; END; } { 1000000008;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000007; InColumnHeading=Yes } { 1000000020;CheckBox;6109;440 ;1124 ;440 ;Name=DoValidate; ParentControl=1000000000; InColumn=Yes; ShowCaption=No; CaptionML=[ENU=Validate; PLK=Validate]; SourceExpr=Bold; OnValidate=BEGIN IF oDontChangeValidation THEN ERROR(''); CASE TRUE OF NumberFormat='': Bold := FALSE;// non importable field END; END; } { 1000000024;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000020; InColumnHeading=Yes } { 1000000021;MenuButton;2750;9350;2200;550 ;Name=fFieldSelect; HorzGlue=Left; VertGlue=Bottom; CaptionML=[ENU=&Fuction; PLK=&Funkcje]; Menu=MENUITEMS { { ID=1000000022; CaptionML=[ENU=Inverse selection; PLK=&Odwr¢† zaznaczenie]; OnPush=BEGIN RecCopy := Rec; FILTERGROUP(10); SETFILTER(NumberFormat,'<>%1',''); // all importable SETFILTER(Formula2,'%1',''); // non PK IF FIND('-') THEN REPEAT Underline := NOT Underline; MODIFY; UNTIL NEXT=0; SETRANGE(Formula2); SETRANGE(NumberFormat); CurrForm.UPDATE(FALSE); FILTERGROUP(0); Rec := RecCopy; Underline := NOT Underline; END; } { ID=1000000023; CaptionML=[ENU=Select all; PLK=&Importuj wszystkie]; OnPush=BEGIN SelectAllToImport; END; } { ID=1000000017; MenuItemType=Separator } { ID=1000000019; CaptionML=[ENU=Set &source column; PLK=Ustaw &kolumn© «r¢dˆow¥]; OnPush=BEGIN SourceFieldLookup; END; } } } { 1000000034;MenuButton;330;9350;2200 ;550 ;Name=fFieldValidate; HorzGlue=Left; VertGlue=Bottom; CaptionML=[ENU=&Validate; PLK=&Walidacja]; Menu=MENUITEMS { { ID=1000000038; CaptionML=[ENU=Inverse Validate settings; PLK=Odwr¢† zaznaczenie]; OnPush=BEGIN RecCopy := Rec; FILTERGROUP(10); SETFILTER(NumberFormat,'<>%1',''); IF FIND('-') THEN REPEAT Bold := NOT Bold; MODIFY; UNTIL NEXT=0; SETRANGE(NumberFormat); FILTERGROUP(0); Rec := RecCopy; Bold := NOT Bold; CurrForm.UPDATE(FALSE); END; } { ID=1000000039; CaptionML=[ENU=Validate All; PLK=Waliduj wszystkie]; OnPush=BEGIN FILTERGROUP(10); SETFILTER(NumberFormat,'<>%1',''); MODIFYALL(Bold,TRUE); SETRANGE(NumberFormat); CurrForm.UPDATE(FALSE); FILTERGROUP(0); END; } } } { 1000000010;CheckBox;5060;8690 ;440 ;440 ;Name=ShowPKCheckBox; HorzGlue=Left; VertGlue=Bottom; ShowCaption=No; CaptionML=[ENU=Hide required and non-importable; PLK=Ukryj pola nieimportowalne]; SourceExpr=HideUnchangeable; OnAfterValidate=BEGIN enableConstFieldsView; CurrForm.UPDATE(FALSE); //NEXT(-1); END; } { 1000000011;Label ;5500 ;8690 ;4180 ;440 ;HorzGlue=Left; VertGlue=Bottom; ParentControl=1000000010; LeaderDots=No } { 1000000012;CheckBox;5060;8140 ;440 ;440 ;Name=OnInsertCheckbox; HorzGlue=Left; VertGlue=Bottom; ShowCaption=No; CaptionML=[ENU=Update; PLK=Aktualizujl]; SourceExpr=oFalseOnInsert } { 1000000013;Label ;5500 ;8140 ;4180 ;440 ;HorzGlue=Left; VertGlue=Bottom; ParentControl=1000000012; LeaderDots=No; CaptionML=[ENU=Don't use OnInsert trigger; PLK=Pomiä OnInsert trigger] } { 1000000015;CheckBox;770 ;7590 ;440 ;440 ;Name=InsertCheckBox; VertGlue=Bottom; ShowCaption=No; CaptionML=[ENU=Insert; PLK=Dodaj]; SourceExpr=optInsert; OnPush=BEGIN IF NOT optInsert THEN optUpdate := TRUE; END; } { 1000000016;Label ;1210 ;7590 ;2310 ;440 ;VertGlue=Bottom; ParentControl=1000000015; LeaderDots=No } { 1000000025;CheckBox;770 ;8140 ;440 ;440 ;Name=updateCheckBox; VertGlue=Bottom; ShowCaption=No; CaptionML=[ENU=Update; PLK=Aktualizuj]; SourceExpr=optUpdate; OnPush=BEGIN IF NOT optUpdate THEN optInsert := TRUE; END; } { 1000000026;Label ;1210 ;8140 ;2310 ;440 ;VertGlue=Bottom; ParentControl=1000000025; LeaderDots=No } { 1000000029;CheckBox;5060;7590 ;440 ;440 ;Name=doDelayedInsert; VertGlue=Bottom; ShowCaption=No; CaptionML=[ENU=Delayed INSERT; PLK=Op¢«niony INSERT]; SourceExpr=optDelayedInsert } { 1000000030;Label ;5500 ;7590 ;4180 ;440 ;HorzGlue=Left; VertGlue=Bottom; ParentControl=1000000029; LeaderDots=No } } CODE { VAR Field@1000000003 : Record 2000000041; UEICode@1000000016 : Codeunit 99991; RecCopy@1000000009 : Record 370; optInsert@1000000002 : Boolean; optUpdate@1000000020 : Boolean; optDelayedInsert@1000000021 : Boolean; importerOptions@1000000010 : Integer; TableNo@1000000007 : Integer; ColumnFilter@1000000011 : Text[1024]; Text001@1000000001 : TextConst 'ENU=Nagˆowek w Excelu;PLK=Excel Header'; oDontChangeOptions@1000000012 : Boolean; oDontChangeMapping@1000000013 : Boolean; oFalseOnInsert@1000000017 : Boolean; oDontChangeValidation@1000000019 : Boolean; HideUnchangeable@1000000004 : Boolean; Text002@1000000005 : TextConst 'ENU=This is primary key field. You cannot exclude it;PLK=To jet pole z klucza gˆ¢wnego. Nie mo¾na wyˆ¥czy† tego pola.'; Text003@1000000008 : TextConst 'ENU=This if FlowFiled or FlowFilter. You cannot import anything to this type field.;PLK=To pole jest typu FlowFiled lub FlowFilter. Nie mo¾na importowa† danych do tego typu pola'; Text004@1000000014 : TextConst 'ENU=Two sources cannot be mapped to one target: Mapping to field %1 already exist (from %2);PLK=Nie mo¾na mapowa† dw¢ch «r¢deˆ w jedno pole docelowe: Mapowanie do pola %1 ju¾ istnieje (z kolumny %2)'; Text005@1000000015 : TextConst 'ENU=There is no field %2 in table no %1;PLK=W tabeli nr %1 nie ma pola %2'; Text006@1000000000 : TextConst 'ENU=unnamed;PLK=bez nazwy'; Text007@1000000018 : TextConst 'ENU=Insert constans instead of value from Excel column;PLK="Przypisa† staˆ¥ zamiast warto˜ci z kolumny ? "'; Text008@1000000006 : TextConst 'ENU=!!no source defined!!;PLK="!!brak «r¢dˆa!! "'; PROCEDURE testForBit@1000000037(BitNo@1000000000 : Integer;value@1000000001 : Integer) : Boolean; VAR ; BEGIN // test if bit BitNo is set in word Value IF (BitNo >=0) AND (BitNo < 32) THEN EXIT( POWER(2,BitNo) <= (value MOD POWER(2,BitNo+1)) ); END; PROCEDURE enableConstFieldsView@1000000004(); BEGIN FILTERGROUP(2); IF HideUnchangeable THEN BEGIN SETFILTER(NumberFormat,'<>%1',''); // only importable fields END ELSE BEGIN SETRANGE(NumberFormat); END; FILTERGROUP(0); IF FIND('=') THEN ; END; PROCEDURE enableOptions@1000000003(); VAR en@1000000000 : Boolean; BEGIN //CurrForm.Importcheckbox.ENABLED(NOT oDontChangeOptions); //CurrForm.updatecheckbox.ENABLED(NOT oDontChangeOptions); CurrForm.OnInsertCheckbox.ENABLED(NOT oDontChangeOptions); END; PROCEDURE FindFieldByName@1000000008(VAR Field@1000000000 : Record 2000000041;TabNo@1000000001 : Integer;Fname@1000000002 : Text[50]); BEGIN Field.RESET; Field.SETRANGE(TableNo,TabNo); Field.SETRANGE(Class,Field.Class::Normal); Field.SETFILTER(FieldName,'@'+Fname+'*'); IF NOT Field.FIND('-') THEN ERROR(Text005,TabNo,Fname); END; PROCEDURE setParameters@1000000000(TabNo@1000000001 : Integer;opt@1000000000 : Integer;ColFilter@1000000002 : Text[1024]); BEGIN TableNo := TabNo; importerOptions := opt; ColumnFilter := ColFilter; calcOptions; enableOptions; END; PROCEDURE calcOptions@1000000013(); BEGIN IF importerOptions MOD 4 = 0 THEN importerOptions += 3; optInsert := testForBit(0,importerOptions); optUpdate := testForBit(1,importerOptions); optDelayedInsert := testForBit(2,importerOptions); oFalseOnInsert := testForBit(8,importerOptions); oDontChangeOptions := testForBit(10,importerOptions); oDontChangeMapping := testForBit(11,importerOptions); oDontChangeValidation := testForBit(12,importerOptions); END; PROCEDURE getOptions@1000000001() : Integer; BEGIN importerOptions := 0; IF optInsert THEN importerOptions += 1; IF optUpdate THEN importerOptions += 2; IF optDelayedInsert THEN importerOptions += 4; IF oFalseOnInsert THEN importerOptions += 256; EXIT(importerOptions); END; PROCEDURE TargetFieldLookup@1000000005(VAR FieldName@1000000002 : Text[50]) : Integer; VAR Field@1000000001 : Record 2000000041; FieldChooseForm@1000000000 : Form 99992; BEGIN IF TableNo = 0 THEN EXIT; IF oDontChangeMapping THEN EXIT; Field.RESET; Field.FILTERGROUP(2); Field.SETRANGE(TableNo,TableNo); Field.SETRANGE(Class,Field.Class::Normal); IF ColumnFilter<>'' THEN Field.SETFILTER("No.",ColumnFilter); Field.FILTERGROUP(0); CLEAR(FieldChooseForm); FieldChooseForm.LOOKUPMODE(TRUE); FieldChooseForm.SETTABLEVIEW(Field); IF FieldChooseForm.RUNMODAL = ACTION::LookupOK THEN BEGIN FieldChooseForm.GETRECORD(Field); FieldName := Field.FieldName; EXIT(Field."No."); END; END; PROCEDURE validateMapTo@1000000006(); VAR xlBuffer2@1000000000 : Record 370; xlBuffer3@1000000003 : Record 370; i@1000000002 : Integer; OtherMapSoure@1000000001 : Text[50]; BEGIN END; PROCEDURE SourceFieldLookup@1000000009(); VAR xlBuffer@1000000002 : Record 370; SourceFields@1000000000 : TEMPORARY Record 370; SourceFieldLookupFrm@1000000001 : Form 99994; BEGIN xlBuffer.RESET; xlBuffer.SETRANGE("Column No.",1,256); xlBuffer.SETRANGE("Row No.",UEICode.FieldMappingMinRange,UEICode.FieldMappingMaxRange); xlBuffer.SETFILTER("Cell Value as Text",'<>%1',''); IF xlBuffer.FIND('-') THEN REPEAT IF NOT SourceFields.GET(0,xlBuffer."Column No.") THEN BEGIN SourceFields := xlBuffer; SourceFields."Row No." := 0; SourceFields.INSERT; END; UNTIL xlBuffer.NEXT = 0; SourceFields.FIND('-'); IF FORM.RUNMODAL(FORM::"UEI - Source Field List",SourceFields) = ACTION::LookupOK THEN BEGIN "Cell Value as Text" := SourceFields."Cell Value as Text"; Formula3 := ''; Underline := TRUE; MODIFY; RENAME("Row No.", SourceFields."Column No."); END END; PROCEDURE cleanMappingInfo@1000000014(VAR CurrRec@1000000000 : Record 370); BEGIN WITH CurrRec DO BEGIN Bold := FALSE; // fire VALIDATE Formula := ''; // Destinaiton Field Name Comment := ''; // Destinaiton Field No. Formula2 := '';// Primary Key Field No. Formula3 := '';// Formula4 := '';// Destination Field Type NumberFormat := ''; // Importable Underline := FALSE; // Selected to import END; END; PROCEDURE fillMappingInfo@1000000016(VAR CurrRec@1000000002 : Record 370;Field@1000000000 : Record 2000000041); VAR i@1000000001 : Integer; BEGIN WITH CurrRec DO BEGIN Formula := Field.FieldName; // Destinaiton Field Name Comment := FORMAT(Field."No.",0,2); // Destinaiton Field No. Formula4 := FORMAT(Field.Type); // Destination Field Type IF Field.Class=Field.Class::Normal THEN NumberFormat := 'Importable'; // Importable Underline := // Selected to import ("Cell Value as Text" <>'') OR (Formula3 <>''); i := UEICode.checkPrimaryKeyFieldNo(TableNo,Field."No."); IF i > 0 THEN BEGIN Formula2 := 'KeyField'+FORMAT(i,0,2); // Primary Key Field No. IF Field.Class=Field.Class::Normal THEN NumberFormat := 'Required'; END; END; END; PROCEDURE SelectAllToImport@1000000010(); BEGIN RecCopy := Rec; FILTERGROUP(10); SETFILTER(NumberFormat,'<>%1',''); SETRANGE(Underline,FALSE); IF FIND('-') THEN REPEAT Underline := ((Formula3 <>'') OR ("Cell Value as Text" <>'')) AND (ActiveMappingExists(Comment,TRUE,Rec) = ''); MODIFY; UNTIL NEXT=0; SETRANGE(NumberFormat); SETRANGE(Underline); FILTERGROUP(0); CurrForm.UPDATE(FALSE); Rec := RecCopy; END; PROCEDURE ActiveMappingExists@1000000007(DestFieldFilter@1000000001 : Text[30];IsActive@1000000000 : Boolean;currRec@1000000003 : Record 370) retVal : Text[250]; VAR tempFMap@1000000002 : Record 370; BEGIN tempFMap.RESET; tempFMap.SETRANGE(Comment,DestFieldFilter); IF IsActive THEN tempFMap.SETRANGE(Underline,TRUE); IF tempFMap.FIND('-') THEN REPEAT IF (tempFMap."Row No." <> currRec."Row No.") OR (tempFMap."Column No." <> currRec."Column No.") THEN BEGIN // another mapping found IF tempFMap."Cell Value as Text" <> '' THEN EXIT(tempFMap."Cell Value as Text"); EXIT(Text006); END; UNTIL tempFMap.NEXT =0; EXIT(''); END; PROCEDURE mapDescriptor@1000000002() : Text[250]; VAR t@1000000000 : Text[250]; BEGIN t := "Cell Value as Text"; IF t = '' THEN t := Text008; EXIT(STRSUBSTNO('%1->%2(%3)',t,Formula,Comment)) END; BEGIN { // // Universal Excel Importer // (c) 2006-2007 Slawek Guzek, sguzek@onet.pl // } END. } } OBJECT Form 99992 UEI - Field Choose { OBJECT-PROPERTIES { Date=07-03-18; Time=23:13:34; Modified=Yes; Version List=Universal Excel Importer v1.1; } PROPERTIES { Width=14400; Height=6710; Editable=No; CaptionML=[ENU=Choose target field; PLK=Wybierz pole docelowe]; TableBoxID=1000000000; SourceTable=Table2000000041; } CONTROLS { { 1000000000;TableBox;220 ;220 ;13960;5500 ;HorzGlue=Both; VertGlue=Both } { 1000000003;TextBox;0 ;0 ;1700 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr="No." } { 1000000004;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000003; InColumnHeading=Yes } { 1000000005;TextBox;1693 ;0 ;3740 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr=FieldName } { 1000000006;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000005; InColumnHeading=Yes } { 1000000001;TextBox;6085 ;440 ;3740 ;440 ;ParentControl=1000000000; InColumn=Yes; SourceExpr="Field Caption" } { 1000000002;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000001; InColumnHeading=Yes } { 1000000007;TextBox;9173 ;0 ;1760 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr=Type } { 1000000008;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000007; InColumnHeading=Yes } { 1000000009;TextBox;10933;0 ;1870 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr=Len } { 1000000010;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000009; InColumnHeading=Yes } { 1000000011;CommandButton;7140;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Default=Yes; PushAction=LookupOK; InvalidActionAppearance=Hide } { 1000000012;CommandButton;9560;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Cancel=Yes; PushAction=LookupCancel; InvalidActionAppearance=Hide } { 1000000013;CommandButton;11980;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; PushAction=FormHelp } } CODE { BEGIN { // // Universal Excel Importer // (c) 2006-2007 Slawek Guzek, sguzek@onet.pl // } END. } } OBJECT Form 99993 UEI - Table List { OBJECT-PROPERTIES { Date=07-03-18; Time=23:14:20; Modified=Yes; Version List=Universal Excel Importer v1.1; } PROPERTIES { Width=11660; Height=6710; Editable=No; CaptionML=[ENU=Choose destination table; PLK=Wybierz tabel© docelow¥]; InsertAllowed=No; DeleteAllowed=No; ModifyAllowed=No; TableBoxID=1000000000; LookupMode=Yes; SourceTable=Table2000000001; SourceTableView=SORTING(Type,Company Name,ID) WHERE(Type=CONST(Table)); } CONTROLS { { 1000000000;TableBox;220 ;220 ;11220;5500 ;HorzGlue=Both; VertGlue=Both } { 1000000001;TextBox;0 ;0 ;1923 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr=ID } { 1000000002;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000001; InColumnHeading=Yes } { 1000000003;TextBox;0 ;0 ;4400 ;0 ;HorzGlue=Both; ParentControl=1000000000; InColumn=Yes; SourceExpr=Name } { 1000000004;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000003; InColumnHeading=Yes } { 1000000007;TextBox;0 ;0 ;4400 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr=Caption } { 1000000008;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000007; InColumnHeading=Yes } { 1000000009;CommandButton;4400;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Default=Yes; PushAction=LookupOK; InvalidActionAppearance=Hide } { 1000000010;CommandButton;6820;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Cancel=Yes; PushAction=LookupCancel; InvalidActionAppearance=Hide } { 1000000011;CommandButton;9240;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; PushAction=FormHelp } } CODE { PROCEDURE GetTableNo@1000000000() : Integer; BEGIN EXIT(ID); END; BEGIN { // // Universal Excel Importer // (c) 2006-2007 Slawek Guzek, sguzek@onet.pl // } END. } } OBJECT Form 99994 UEI - Source Field List { OBJECT-PROPERTIES { Date=07-03-18; Time=23:15:31; Modified=Yes; Version List=Universal Excel Importer v1.1; } PROPERTIES { Width=8690; Height=6710; Editable=No; CaptionML=[ENU=Source column; PLK=Kolumna «r¢dˆowa]; TableBoxID=1000000000; LookupMode=Yes; SourceTable=Table370; } CONTROLS { { 1000000000;TableBox;220 ;220 ;8250 ;5500 ;HorzGlue=Both; VertGlue=Both; HeadingHeight=880 } { 1000000001;TextBox;0 ;0 ;1153 ;0 ;ParentControl=1000000000; InColumn=Yes; SourceExpr="Column No." } { 1000000002;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000001; InColumnHeading=Yes } { 1000000003;TextBox;1693 ;0 ;1540 ;0 ;HorzGlue=Left; ParentControl=1000000000; InColumn=Yes; SourceExpr=xlColID } { 1000000004;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000003; InColumnHeading=Yes } { 1000000005;TextBox;0 ;0 ;4400 ;0 ;HorzGlue=Both; ParentControl=1000000000; InColumn=Yes; SourceExpr="Cell Value as Text" } { 1000000006;Label ;0 ;0 ;0 ;0 ;ParentControl=1000000005; InColumnHeading=Yes } { 1000000007;CommandButton;1430;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Default=Yes; PushAction=LookupOK; InvalidActionAppearance=Hide } { 1000000008;CommandButton;3850;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; Cancel=Yes; PushAction=LookupCancel; InvalidActionAppearance=Hide } { 1000000009;CommandButton;6270;5940;2200;550; HorzGlue=Right; VertGlue=Bottom; PushAction=FormHelp } } CODE { BEGIN END. } } OBJECT Codeunit 99991 Universal Excel Importer { OBJECT-PROPERTIES { Date=07-03-18; Time=23:10:37; Modified=Yes; Version List=Universal Excel Importer v1.1; } PROPERTIES { OnRun=VAR t@1000000000 : Text[120]; BEGIN ImportData(0,'',0); END; } CODE { VAR Text000@1000000001 : TextConst 'ENU=Open source file;PLK=Otw¢rz plik «r¢dˆowy z danymi'; Text001@1000000000 : TextConst 'ENU=Import/update of data finished successfully;PLK=Import/aktualizacja danych zakoäczona pomy˜lnie'; Text002@1000000004 : TextConst 'ENU=Importing...\@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@;PLK=Wczytywanie rekord¢w...\@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'''; Text003@1000000005 : TextConst 'ENU=''No such option: %1'';PLK=Nieznana opcja: %1'; Text004@1000000006 : TextConst 'ENU=The Excel worksheet %1 does not exist.;PLK=Arkusz programu Excel (%1) nie istnieje.'; Text005@1000000003 : TextConst 'ENU=No header information in buffer row %1;PLK=Brak nagˆ¢wka w wierszu %1 bufora'; Text006@1000000007 : TextConst 'ENU=''No required primary key field "%1" (%2) in user filter;PLK=Brak wymaganego pola klucza gˆ¢wnego "%1" (%2) w filtrze'; Text007@1000000002 : TextConst 'ENU=Reading Excel worksheet...\\;PLK=Czytanie arkusza programu Excel...\\'; Text008@1000000008 : TextConst 'ENU=Import stopped at user request;PLK=Import przerwany na ¾¥danie u¾ytkownika'; Text009@1000000009 : TextConst 'ENU=''Select Import, Update, or both options'';PLK=Wybierz import, aktualizacj©, lub obie opcje importu'; Text010@1000000010 : TextConst 'ENU=''No field mapping information in buffer'';PLK="Brak informacji o mapowaniu kolumn excela do p¢l tabeli w buforze "'; Text011@1000000011 : TextConst 'ENU="Fields:\%1\were not imported. Fields type of\%2\can not be read form Excel. ";PLK=Pola:\%1\nie zostaˆy zaimportowane. Typy danych:\%2\nie s¥ obsˆugiwane'; XlWrkSht@1000000015 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{00020820-0000-0000-C000-000000000046}:Unknown Automation Server.Worksheet"; XlApp@1000000014 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{00024500-0000-0000-C000-000000000046}:Unknown Automation Server.Application"; XlWrkBk@1000000013 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{00020819-0000-0000-C000-000000000046}:Unknown Automation Server.Workbook"; warn@1000000012 : Boolean; Text012@1000000016 : TextConst 'ENU=No such table no: %1;PLK=Niepoprawny numer tabeli: %1'; Text013@1000000017 : TextConst 'ENU=Intenal error: No primary key info in buffer table;PLK=Bˆ¥d wewn©trzny: brak informacji o kluczu gˆ¢wnym w tabeli buforowej'; Text014@1000000018 : TextConst 'PLK=Bˆ©dny format pola typu ''BigInteger'': %1'; PROCEDURE ImportData@1(tableNo@1000000015 : Integer;columnFilter@1000000000 : Text[1024];importOptions@1000000003 : Integer) : Integer; VAR filename@1000000002 : Text[250]; sheetName@1000000001 : Text[50]; BEGIN filename :=''; sheetName:=''; EXIT( ImportDataFromFile(filename,sheetName,tableNo,0,columnFilter,importOptions) ); END; PROCEDURE ImportDataFromFile@2(VAR fileName@1000000004 : Text[512];VAR sheetName@1000000003 : Text[50];tableNo@1000000001 : Integer;headerRow@1000000006 : Integer;columnList@1000000000 : Text[1024];ImporterOptions@1000000002 : Integer) : Integer; VAR xlBuffer@1000000005 : Record 370; fieldMapping@1000000009 : TEMPORARY Record 370; recRef@1000000017 : RecordRef; columnFilter@1000000008 : Text[1024]; i@1000000007 : Integer; optInsert@1000000011 : Boolean; optUpdate@1000000012 : Boolean; optNoOnInsertTrigger@1000000014 : Boolean; optDelayedInsert@1000000013 : Boolean; rowCount@1000000019 : Integer; statusWindow@1000000015 : Dialog; recordFound@1000000016 : Boolean; lineCount@1000000018 : Integer; rowFilter@1000000020 : Text[10]; batchImport@1000000021 : Boolean; destTableNo@1000000022 : Text[30]; searchByOption@1000000010 : 'FieldCaption,FieldName,FieldNo'; validateOption@1000000023 : 'All,None,FileDefined'; BEGIN IF ImporterOptions MOD 4 = 0 THEN ImporterOptions := 3; // import OR update IF SelectExcelSource(fileName,sheetName,xlBuffer) < 0 THEN EXIT(-1); headerRow := readHeader(fileName,sheetName,headerRow,tableNo,xlBuffer); IF NOT testTableNo(tableNo) THEN EXIT(-1); i := ROUND((ImporterOptions MOD 4)/2,1,'<'); optInsert := i IN [1,3]; optUpdate := i IN [2,3]; CASE TRUE OF testForBit(5,ImporterOptions) : searchByOption := searchByOption::FieldNo; testForBit(4,ImporterOptions) : searchByOption := searchByOption::FieldName; ELSE searchByOption := searchByOption::FieldCaption; END; CASE TRUE OF testForBit(7,ImporterOptions) : validateOption := validateOption::FileDefined; testForBit(6,ImporterOptions) : validateOption := validateOption::None; ELSE validateOption := validateOption::All; END; generatePrimaryKeyInfo(tableNo,xlBuffer); checkUserColumnFilter(xlBuffer,columnList); generateFieldMapping(tableNo,columnList,headerRow,ImporterOptions,xlBuffer); columnFilter := ChooseColumnsToImport(tableNo,columnList,ImporterOptions,xlBuffer); readFieldMapping(xlBuffer,fieldMapping,ImporterOptions,FieldMappingRowFiler); xlBuffer.SETFILTER("Row No.", '>%1',headerRow); ReadSelectedSheetArea(xlBuffer,fileName,sheetName,STRSUBSTNO('>%1',headerRow),columnFilter); clearExcel; COMMIT; optInsert := testForBit(0,ImporterOptions); optUpdate := testForBit(1,ImporterOptions); optDelayedInsert := testForBit(2,ImporterOptions); optNoOnInsertTrigger := testForBit(8,ImporterOptions); xlBuffer.RESET; xlBuffer.SETFILTER("Row No.", '>%1', headerRow); rowCount := xlBuffer."Row No."; statusWindow.OPEN(Text002); xlBuffer.FIND('-'); REPEAT CLEAR(recRef); recRef.OPEN(tableNo); i := xlBuffer."Row No."; xlBuffer.SETRANGE("Row No.",i); statusWindow.UPDATE(1,ROUND(10000*i/rowCount,1)); recRef.INIT; recordFound := findRecord(recRef,xlBuffer,fieldMapping,searchByOption); IF optInsert AND NOT recordFound THEN BEGIN fillRecord(recRef, xlBuffer, fieldMapping,searchByOption,NOT optDelayedInsert); IF optNoOnInsertTrigger THEN recRef.INSERT(FALSE) ELSE recRef.INSERT(TRUE); END; IF (optInsert AND NOT optDelayedInsert) OR (recordFound AND optUpdate) THEN BEGIN fillRecord(recRef,xlBuffer,fieldMapping,searchByOption,FALSE); IF optNoOnInsertTrigger THEN recRef.MODIFY(FALSE) ELSE recRef.MODIFY(TRUE); END; lineCount += 1; xlBuffer.FIND('+'); xlBuffer.SETRANGE("Row No."); recRef.CLOSE; UNTIL xlBuffer.NEXT = 0 ; statusWindow.CLOSE; generateWarning(fieldMapping); EXIT(lineCount); END; PROCEDURE PrimaryKeyInfoBeginRow@1000000032() : Integer; BEGIN EXIT(-900); END; PROCEDURE PrimaryKeyInfoEndRow@1000000033() : Integer; BEGIN EXIT(-850); END; PROCEDURE ConstantsAreaBeginRow@1000000006() : Integer; BEGIN EXIT(-800); END; PROCEDURE ConstantsAreaEndRow@1000000028() : Integer; BEGIN EXIT(-601); END; PROCEDURE FieldMapBeginRow@1000000036() : Integer; BEGIN EXIT(-600); END; PROCEDURE FieldMapEndRow@1000000038() : Integer; BEGIN EXIT(-1); END; PROCEDURE FieldMappingMaxRange@1000000000() : Integer; BEGIN EXIT(FieldMapEndRow); END; PROCEDURE FieldMappingMinRange@1000000019() : Integer; BEGIN EXIT(PrimaryKeyInfoBeginRow); END; LOCAL PROCEDURE FieldMappingRowFiler@1000000004() : Text[50]; BEGIN EXIT(FORMAT(FieldMappingMinRange,0,2)+'..'+FORMAT(FieldMappingMaxRange,0,2)); END; LOCAL PROCEDURE testTableNo@1000000002(VAR tableNo@1000000000 : Integer) : Boolean; VAR Object@1000000001 : Record 2000000001; BEGIN CASE TRUE OF tableNo > 0: IF NOT Object.GET(Object.Type::Table,'',tableNo) THEN BEGIN clearExcel; ERROR(Text012, tableNo) END ELSE EXIT(TRUE); tableNo = 0: BEGIN COMMIT; IF FORM.RUNMODAL(FORM::"UEI - Table List",Object) = ACTION::LookupOK THEN BEGIN tableNo := Object.ID; EXIT(TRUE); END; END; END; EXIT(FALSE); END; LOCAL PROCEDURE LeaveCharacters@1000000015(text@1000000000 : Text[512];charsToLeave@1000000001 : Text[255]) newText : Text[512]; VAR l@1000000002 : Integer; t@1000000003 : Text[1]; BEGIN l := STRLEN(text); WHILE l > 0 DO BEGIN t[1] := text[l]; IF STRPOS(charsToLeave,t) > 0 THEN newText := t + newText; l-= 1; END; EXIT(newText); END; LOCAL PROCEDURE testForBit@1000000037(BitNo@1000000000 : Integer;value@1000000001 : Integer) : Boolean; VAR ; BEGIN // test if bit BitNo is set in word Value IF (BitNo >=0) AND (BitNo < 32) THEN EXIT( POWER(2,BitNo) <= (value MOD POWER(2,BitNo+1)) ); END; LOCAL PROCEDURE findFieldNoByCaption@1000000009(tableNo@1000000002 : Integer;fieldCaption@1000000001 : Text[100]) columnNo : Integer; VAR FieldList@1000000000 : Record 2000000041; BEGIN FieldList.RESET; FieldList.SETRANGE(TableNo, tableNo); fieldCaption := UPPERCASE(fieldCaption); FieldList.FIND('-'); REPEAT IF UPPERCASE(FieldList."Field Caption") = fieldCaption THEN EXIT (FieldList."No."); UNTIL FieldList.NEXT=0; EXIT(0); END; LOCAL PROCEDURE findFieldNoByName@1000000016(tableNo@1000000002 : Integer;fieldName@1000000001 : Text[40]) columnNo : Integer; VAR FieldList@1000000000 : Record 2000000041; BEGIN FieldList.RESET; FieldList.SETRANGE(TableNo, tableNo); fieldName := UPPERCASE(fieldName); FieldList.FIND('-'); REPEAT IF UPPERCASE(FieldList.FieldName) = fieldName THEN EXIT (FieldList."No."); UNTIL FieldList.NEXT=0; EXIT(0); END; LOCAL PROCEDURE findTextInList@1000000020(list@1000000001 : Text[1024];textToSearchFor@1000000000 : Text[250];onlyFullMatch@1000000003 : Boolean) : Integer; VAR i@1000000002 : Integer; optionNo@1000000004 : Integer; beginOptionText@1000000006 : Integer; optionTextLen@1000000007 : Integer; optionListLen@1000000008 : Integer; textToSearchForLen@1000000009 : Integer; optionText@1000000005 : Text[250]; BEGIN textToSearchFor := UPPERCASE(textToSearchFor); textToSearchForLen := STRLEN(textToSearchFor); optionListLen := STRLEN(list); beginOptionText := 1; i := 1; WHILE i < optionListLen DO BEGIN WHILE (i <= optionListLen) AND (list[i] <> ',') DO i += 1; optionTextLen := i - beginOptionText; optionText := COPYSTR(list,beginOptionText,optionTextLen); IF onlyFullMatch THEN BEGIN IF UPPERCASE(optionText) = textToSearchFor THEN EXIT(optionNo); END ELSE IF UPPERCASE(COPYSTR(optionText,1,textToSearchForLen)) = textToSearchFor THEN EXIT(optionNo); optionNo += 1; i += 1; beginOptionText := i; END; optionText := ''; EXIT(-1); END; LOCAL PROCEDURE clearExcel@1000000010(); BEGIN IF NOT ISCLEAR(XlApp) THEN BEGIN XlWrkBk.Close(FALSE); XlApp.Quit; CLEAR(XlApp); END; END; LOCAL PROCEDURE openExcelSheet@1000000008(fileName@1000000001 : Text[512];sheetName@1000000000 : Text[50];VAR XlWrkSht@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{00020820-0000-0000-C000-000000000046}:Unknown Automation Server.Worksheet"); VAR XlWrkshts@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{000208D8-0000-0000-C000-000000000046}:Unknown Automation Server._Worksheet"; i@1000000004 : Integer; BEGIN IF ISCLEAR(XlApp) THEN BEGIN IF NOT CREATE(XlApp,TRUE) THEN ERROR(Text000); END ELSE IF NOT ISCLEAR(XlWrkSht) THEN IF (XlWrkBk.FullName = UPPERCASE(fileName)) AND (UPPERCASE(sheetName) = UPPERCASE(XlWrkSht.Name)) THEN EXIT; XlApp.Workbooks._Open(fileName,TRUE); XlWrkBk := XlApp.ActiveWorkbook; i := XlWrkBk.Worksheets.Count; WHILE i > 0 DO BEGIN XlWrkshts := XlWrkBk.Worksheets.Item(i); IF UPPERCASE(sheetName) = UPPERCASE(XlWrkshts.Name) THEN i := 0; i -= 1; END; IF i < 0 THEN XlWrkSht := XlWrkBk.Worksheets.Item(sheetName) ELSE BEGIN XlWrkBk.Close(FALSE); XlApp.Quit; CLEAR(XlApp); ERROR(Text004,sheetName); END; END; LOCAL PROCEDURE evaluateOption@1000000018(VAR fieldRef@1000000000 : FieldRef;optionText@1000000003 : Text[30];searchOption@1000000002 : 'FieldCaption,FieldName,FieldNo') : Integer; VAR optionNo@1000000001 : Integer; optionList@1000000004 : Text[250]; thousandsSeparator@1000000005 : Text[1]; BEGIN thousandsSeparator[1] := 255; CASE searchOption OF searchOption::FieldCaption: optionList := UPPERCASE(fieldRef.OPTIONCAPTION) ELSE optionList := UPPERCASE(fieldRef.OPTIONSTRING) END; optionNo := findTextInList(optionList,optionText,FALSE); IF optionNo >= 0 THEN EXIT(optionNo); optionList := DELCHR(optionText,'<=>','0123456789'+thousandsSeparator) ; IF optionList <> '' THEN EXIT(-1); EVALUATE(optionNo, optionText); EXIT(optionNo); END; LOCAL PROCEDURE SelectExcelSource@1000000001(VAR FileName@1000000000 : Text[100];VAR SheetName@1000000001 : Text[50];VAR xlBuffer@1000000002 : Record 370) : Integer; VAR DialogWindow@1000000003 : Codeunit 412; BEGIN IF (FileName = '' ) OR (NOT EXISTS(FileName)) THEN BEGIN FileName := DialogWindow.OpenFile(Text000, '', 2{=Excel}, '', 0{=Open}); IF FileName = '' THEN EXIT (-1); END; IF SheetName = '' THEN SheetName := xlBuffer.SelectSheetsName(FileName); IF SheetName = '' THEN EXIT (-1); END; LOCAL PROCEDURE ReadSelectedSheetArea@1000000021(VAR xlBuffer@1000000009 : Record 370;fileName@1000000008 : Text[512];sheetName@1000000007 : Text[50];rowList@1000000014 : Text[1024];columnList@1000000006 : Text[1024]) : Integer; VAR XlWrkshts@1000000010 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{000208D8-0000-0000-C000-000000000046}:Unknown Automation Server._Worksheet"; XlRange@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.2:{00020846-0000-0000-C000-000000000046}:Unknown Automation Server.Range"; currRow@1000000005 : Integer; currCol@1000000003 : Integer; MaxRow@1000000004 : Integer; MaxCol@1000000002 : Integer; Window@1000000001 : Dialog; t@1000000015 : Text[100]; row@1000000016 : Record 2000000026; col@1000000017 : Record 2000000026; cleanXLApp@1000000013 : Boolean; untilFirst@1000000019 : Boolean; firstFound@1000000022 : Boolean; rowCount@1000000020 : Integer; cellValue@1000000021 : Text[1024]; lastRow@1000000023 : Integer; i@1000000024 : Integer; BEGIN // open Excel book openExcelSheet(fileName,sheetName,XlWrkSht); IF COPYSTR(rowList,1,1) = '-' THEN BEGIN untilFirst := TRUE; rowList := COPYSTR(rowList,2); END; IF rowList <> '' THEN BEGIN row.FILTERGROUP(8); row.SETFILTER(Number,rowList); row.FILTERGROUP(0); END; IF columnList <> '' THEN BEGIN col.FILTERGROUP(8); col.SETFILTER(Number,columnList); col.FILTERGROUP(0); END; Window.OPEN( Text007 + '@1@@@@@@@@@@@@@@@@@@@@@@@@\'); Window.UPDATE(1,0); WITH xlBuffer DO BEGIN DELETEALL; XlRange := XlWrkSht.Range(GetExcelReference(5)).SpecialCells(11); MaxRow := XlRange.Row; MaxCol := XlRange.Column; rowCount := 0; currRow := 1; REPEAT currCol := 1; row.SETRANGE(Number,currRow); IF (rowList = '') OR (row.FIND('-')) THEN BEGIN // row No. in filter REPEAT col.SETRANGE(Number,currCol); IF (columnList = '') OR (col.FIND('-')) THEN BEGIN // column No in filter INIT; VALIDATE("Row No.",currRow); VALIDATE("Column No.",currCol); cellValue := DELCHR(FORMAT(XlWrkSht.Range(xlColID + xlRowID).Value),'<>',' '); IF cellValue <> '' THEN BEGIN "Cell Value as Text" := COPYSTR(cellValue,1,250); cellValue := DELCHR(FORMAT(XlWrkSht.Range(xlColID + xlRowID).Text),'<>',' '); Comment := COPYSTR(cellValue,1,250); cellValue := DELCHR(FORMAT(XlWrkSht.Range(xlColID + xlRowID).Value2),'<>',' '); Formula := COPYSTR(cellValue,1,250); cellValue := FORMAT(XlWrkSht.Range(xlColID + xlRowID).Font.Italic); EVALUATE(Italic,cellValue); cellValue := FORMAT(XlWrkSht.Range(xlColID + xlRowID).Font.Bold); EVALUATE(Bold,cellValue); firstFound := TRUE; IF currRow <> lastRow THEN BEGIN rowCount += 1; lastRow := currRow; END; INSERT; END; END; currCol += 1; UNTIL currCol > MaxCol; END; currRow += 1; Window.UPDATE(1,ROUND(currRow / MaxRow * 10000,1)); UNTIL (currRow > MaxRow) OR (untilFirst AND firstFound) ; END; Window.CLOSE; EXIT(currRow-1); END; LOCAL PROCEDURE checkUserColumnFilter@1000000024(VAR PKFieldList@1000000001 : Record 370;ColumnFilter@1000000000 : Text[1024]) : Boolean; VAR t@1000000002 : Text[100]; Field@1000000006 : Record 2000000041; Column@1000000004 : Record 2000000026; BEGIN // searchOption // d1 d0 // 0 0 - fieldCaption // 0 1 - fieldName // 1 0 - fieldNo PKFieldList.RESET; PKFieldList.SETRANGE("Row No.",PrimaryKeyInfoBeginRow,PrimaryKeyInfoEndRow); PKFieldList.SETRANGE("Column No.",0); IF NOT PKFieldList.FIND('-') THEN BEGIN clearExcel; ERROR(Text013); END; IF ColumnFilter = '' THEN EXIT(TRUE); Column.FILTERGROUP(8); Column.SETFILTER(Number,ColumnFilter); Column.FILTERGROUP(0); IF PKFieldList.FIND('-') THEN REPEAT Column.SETRANGE(Number, PKFieldList."Column No."); IF NOT Column.FIND('-') THEN BEGIN clearExcel; ERROR(Text006, PKFieldList.Formula, PKFieldList."Column No."); END; UNTIL PKFieldList.NEXT =0; PKFieldList.RESET; EXIT(TRUE); END; LOCAL PROCEDURE ChooseColumnsToImport@1000000026(tableNo@1000000007 : Integer;ColFilter@1000000001 : Text[1024];VAR options@1000000000 : Integer;VAR xlBuffer@1000000006 : Record 370) columnFilter : Text[1024]; VAR FieldMapDialog@1000000005 : Form 99991; i@1000000004 : Integer; BEGIN CLEAR(FieldMapDialog); COMMIT; FieldMapDialog.setParameters(tableNo,options,ColFilter); FieldMapDialog.LOOKUPMODE(TRUE); IF FieldMapDialog.RUNMODAL <> ACTION::LookupOK THEN BEGIN clearExcel; CLEAR(FieldMapDialog); ERROR(Text008); END; options := FieldMapDialog.getOptions; columnFilter := buildFilterString(xlBuffer); END; LOCAL PROCEDURE buildFilterString@1000000022(VAR xlBuffer@1000000000 : Record 370) : Text[1024]; VAR fieldMapping@1000000006 : TEMPORARY Record 370; itemCount@1000000007 : Integer; FirstItem@1000000005 : Integer; LastItem@1000000004 : Integer; More@1000000003 : Boolean; SelectionFilter@1000000002 : Text[1024]; i@1000000001 : Integer; BEGIN xlBuffer.RESET; xlBuffer.SETRANGE("Row No.", FieldMappingMinRange,FieldMappingMaxRange); xlBuffer.SETRANGE(Underline,TRUE); xlBuffer.SETRANGE("Column No.",1,256); IF xlBuffer.FIND('-') THEN REPEAT itemCount += 1; fieldMapping := xlBuffer; fieldMapping."Row No." := 0; IF NOT fieldMapping.INSERT THEN; UNTIL xlBuffer.NEXT = 0; itemCount := fieldMapping.COUNT; IF itemCount > 0 THEN BEGIN fieldMapping.FIND('-'); WHILE itemCount > 0 DO BEGIN itemCount -= 1; FirstItem := fieldMapping."Column No."; LastItem := FirstItem; More := (itemCount > 0); WHILE More DO BEGIN IF fieldMapping.NEXT = 0 THEN More := FALSE ELSE IF NOT fieldMapping.Bold THEN More := FALSE ELSE BEGIN IF fieldMapping."Column No." - LastItem > 1 THEN More := FALSE ELSE BEGIN LastItem := fieldMapping."Column No."; itemCount -= 1; END; IF (itemCount = 0) THEN More := FALSE; END; END; IF SelectionFilter <> '' THEN SelectionFilter := SelectionFilter + '|'; IF FirstItem = LastItem THEN SelectionFilter := SelectionFilter + FORMAT(FirstItem) ELSE SelectionFilter := SelectionFilter + FORMAT(FirstItem) + '..' + FORMAT(LastItem); IF itemCount > 0 THEN BEGIN fieldMapping.SETRANGE(Bold,TRUE); IF fieldMapping."Column No." - LastItem <= 1 THEN fieldMapping.NEXT; END; END; END; fieldMapping.RESET; EXIT(SelectionFilter); END; LOCAL PROCEDURE findRecord@1000000027(VAR recRef@1000000000 : RecordRef;VAR xlBuffer@1000000009 : Record 370;VAR fieldMapping@1000000004 : Record 370;searchOption@1000000001 : 'FieldCaption,FieldName,FieldNo') : Boolean; VAR fieldRef@1000000011 : FieldRef; cellFound@1000000005 : Boolean; cellValue@1000000012 : Text[262]; cellValue2@1000000002 : Text[262]; fieldNo@1000000007 : Integer; option@1000000008 : Integer; i_value@1000000023 : Integer; dec_value@1000000022 : Decimal; dat_value@1000000021 : Date; tim_value@1000000020 : Time; b_value@1000000019 : Boolean; bi_value@1000000018 : BigInteger; bin_value@1000000017 : Binary[200]; dattim_value@1000000016 : DateTime; datform_value@1000000015 : DateFormula; thousandSeparator@1000000003 : Text[1]; BEGIN thousandSeparator[1] := 255; fieldMapping.RESET; fieldMapping.MODIFYALL(Underline,FALSE); fieldMapping.SETFILTER(Formula2,'<>%1',''); // only PrimaryKey fieldMapping.FIND('-'); REPEAT EVALUATE(fieldNo,fieldMapping.Comment); fieldRef := recRef.FIELD(fieldNo); cellFound := xlBuffer.GET(xlBuffer."Row No.", fieldMapping."Column No."); IF cellFound THEN BEGIN cellValue := xlBuffer."Cell Value as Text"; cellValue2 := xlBuffer.Formula; END; CASE fieldMapping.Formula4 OF // field.type 'Text','Code': IF cellFound THEN BEGIN cellValue2 := DELCHR(cellValue,'<=>', '0123456789'+thousandSeparator); IF STRLEN(cellValue2) = 0 THEN cellValue2 := LeaveCharacters(cellValue,'0123456789') ELSE cellValue2 := DELCHR(cellValue,'<>',' '); fieldRef.VALUE := COPYSTR(cellValue2,1,fieldRef.LENGTH); END ELSE fieldRef.VALUE := ''; 'Boolean': IF cellFound THEN fieldRef.VALUE := calcBool(cellValue) ELSE fieldRef.VALUE := FALSE; 'Date': IF cellFound THEN BEGIN EVALUATE(dat_value, cellValue); fieldRef.VALUE := dat_value; END ; 'Time': IF cellFound THEN BEGIN tim_value := calcTime(cellValue); fieldRef.VALUE := tim_value; END ; 'DateFormula': IF cellFound THEN BEGIN EVALUATE(datform_value, cellValue); fieldRef.VALUE := datform_value; END ; 'DateTime' : IF cellFound THEN BEGIN fieldRef.VALUE := calcDateTime(cellValue,cellValue2); END ; 'BigInteger': IF cellFound THEN BEGIN EVALUATE(bi_value, cellValue); fieldRef.VALUE := bi_value; END ; 'Integer': IF cellFound THEN BEGIN EVALUATE(i_value, cellValue); fieldRef.VALUE := i_value; END ; 'Decimal': IF cellFound THEN BEGIN EVALUATE(dec_value, cellValue); fieldRef.VALUE := dec_value ; END ; 'Option': IF cellFound THEN BEGIN option := evaluateOption(fieldRef,cellValue,searchOption); fieldRef.VALUE := option; END END; UNTIL fieldMapping.NEXT = 0; cellFound := recRef.FIND('=') ; EXIT (cellFound); END; LOCAL PROCEDURE fillRecord@1000000025(VAR recRef@1000000007 : RecordRef;VAR xlBuffer@1000000008 : Record 370;VAR fieldMapping@1000000011 : Record 370;searchOption@1000000024 : 'FieldCaption,FieldName,FieldNo';InsertPKOnly@1000000013 : Boolean) : Boolean; VAR fieldRef@1000000010 : FieldRef; fieldNo@1000000009 : Integer; cellFound@1000000019 : Boolean; cellValue@1000000017 : Text[250]; cellValue2@1000000023 : Text[250]; t@1000000014 : Text[250]; i_value@1000000006 : Integer; dec_value@1000000005 : Decimal; dat_value@1000000004 : Date; tim_value@1000000003 : Time; b_value@1000000002 : Boolean; bi_value@1000000001 : BigInteger; bin_value@1000000000 : Binary[200]; dattim_value@1000000020 : DateTime; datform_value@1000000022 : DateFormula; i@1000000015 : Integer; thousandSeparator@1000000018 : Text[1]; BEGIN thousandSeparator[1] := 255; fieldMapping.RESET; IF InsertPKOnly THEN fieldMapping.SETFILTER(Formula2,'<>%1',''); // only PrimaryKey fieldMapping.SETRANGE(Underline,FALSE); IF fieldMapping.FIND('-') THEN REPEAT cellFound := xlBuffer.GET(xlBuffer."Row No.", fieldMapping."Column No."); IF cellFound THEN BEGIN EVALUATE(fieldNo,fieldMapping.Comment); fieldRef := recRef.FIELD(fieldNo); fieldMapping.Underline := TRUE; fieldMapping.MODIFY; cellValue := xlBuffer."Cell Value as Text"; cellValue2 := xlBuffer.Formula; CASE FORMAT(fieldRef.TYPE) OF 'Text','Code': BEGIN t := DELCHR(cellValue,'<=>', '0123456789'+thousandSeparator); IF STRLEN(t) = 0 THEN // numbers only cellValue := LeaveCharacters(cellValue,'0123456789'); IF fieldMapping.Bold THEN fieldRef.VALIDATE(COPYSTR(DELCHR(cellValue,'<>',' '),1,fieldRef.LENGTH)) ELSE fieldRef.VALUE := COPYSTR(DELCHR(cellValue,'<>',' '),1,fieldRef.LENGTH); END; 'Option' : BEGIN i_value := evaluateOption(fieldRef,cellValue,searchOption); IF i_value >= 0 THEN BEGIN IF fieldMapping.Bold THEN fieldRef.VALIDATE(i_value) ELSE fieldRef.VALUE := i_value; END; END ; 'Integer': BEGIN EVALUATE(i_value, cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(i_value) ELSE fieldRef.VALUE := i_value; END; 'BigInteger': BEGIN bi_value := calcBigInt(cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(bi_value) ELSE fieldRef.VALUE := bi_value; END; 'Decimal': BEGIN dec_value := calcDecimal(cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(dec_value) ELSE fieldRef.VALUE := dec_value; END; 'Date': BEGIN EVALUATE(dat_value, cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(dat_value) ELSE fieldRef.VALUE := dat_value; END; 'Time': BEGIN tim_value := calcTime(cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(tim_value) ELSE fieldRef.VALUE :=tim_value; END; 'DateTime': BEGIN dattim_value := calcDateTime(cellValue,cellValue2); IF fieldMapping.Bold THEN fieldRef.VALIDATE(dattim_value) ELSE fieldRef.VALUE := dattim_value; END; 'DateFormula': BEGIN EVALUATE(datform_value,cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(datform_value) ELSE fieldRef.VALUE := datform_value; END; 'Boolean': BEGIN b_value := calcBool(cellValue); IF fieldMapping.Bold THEN fieldRef.VALIDATE(b_value) ELSE fieldRef.VALUE := b_value; END; ELSE BEGIN warn := TRUE; fieldMapping.NumberFormat :='warn'; fieldMapping.MODIFY; END; END; END; UNTIL fieldMapping.NEXT = 0; EXIT(FALSE); END; LOCAL PROCEDURE calcBigInt@1000000005(txt@1000000000 : Code[50]) bi : BigInteger; VAR i@1000000001 : Integer; tBase@1000000002 : Text[50]; tExp@1000000003 : Text[30]; d@1000000004 : Decimal; BEGIN i := STRPOS(txt,'E'); IF i > 0 THEN BEGIN tBase := COPYSTR(txt,1,i-1); tExp := COPYSTR(txt,i+1); i := 1; CASE tExp[1] OF '+': tExp := COPYSTR(tExp,2); '-': ERROR(Text014,txt); END; EVALUATE(d,tExp); bi := POWER(10,i*d); EVALUATE(d,tBase); bi := d * bi; EXIT(bi); END; EVALUATE(bi,txt); END; LOCAL PROCEDURE calcDecimal@1000000011(txt@1000000000 : Code[50]) dec : Decimal; VAR i@1000000001 : Integer; tBase@1000000002 : Text[50]; tExp@1000000003 : Text[30]; d@1000000004 : Decimal; BEGIN i := STRPOS(txt,'E'); IF i > 0 THEN BEGIN tBase := COPYSTR(txt,1,i-1); tExp := COPYSTR(txt,i+1); i := 1; CASE tExp[1] OF '+': tExp := COPYSTR(tExp,2); '-': BEGIN tExp := COPYSTR(tExp,2); i := -1; END; END; EVALUATE(d,tExp); dec := POWER(10,i*d); EVALUATE(d,tBase); dec := d * dec; EXIT(dec); END; EVALUATE(dec,txt); END; LOCAL PROCEDURE calcBool@1000000012(BoolText@1000000000 : Text[250]) : Boolean; VAR b@1000000001 : Boolean; BEGIN CASE BoolText OF 'true','tak','y','t','yes','1','prawda': EXIT(TRUE); 'false','nie','f','n','no','0','faˆsz': EXIT(FALSE); END; EVALUATE(b,BoolText); EXIT(b); END; LOCAL PROCEDURE calcDateTime@1000000023(DatTimText@1000000000 : Text[100];DatTimText2@1000000009 : Text[100]) : DateTime; VAR ts@1000000005 : Text[2]; dt@1000000001 : DateTime; tim@1000000002 : Time; dat@1000000003 : Date; dec@1000000004 : Decimal; day@1000000006 : Integer; i@1000000007 : Integer; bi@1000000008 : BigInteger; BEGIN ts := ' '; ts[1] := 255; EVALUATE(dat,DatTimText); DatTimText2 := DELCHR(DatTimText2,'<=>',ts); EVALUATE(dec,DatTimText2); i := ROUND(dec,1,'<'); tim := 000000T; tim := tim + ROUND((dec-i)*(1000*60*60*24),1); dt := CREATEDATETIME(dat,tim); EXIT(dt); END; LOCAL PROCEDURE calcTime@1000000013(TimeText@1000000000 : Text[100]) : Time; VAR ts@1000000003 : Text[2]; tim@1000000001 : Time; i@1000000002 : Integer; dec@1000000004 : Decimal; BEGIN ts := ' '; ts[1] := 255; TimeText := DELCHR(TimeText,'<=>',ts); EVALUATE(dec,TimeText); i := ROUND(dec,1,'<'); tim := 000000T; tim := tim + ROUND((dec-i)*(1000*60*60*24),1); EXIT(tim); END; LOCAL PROCEDURE readFieldMapping@1000000007(VAR xlBuffer@1000000001 : Record 370;VAR fieldMapping@1000000000 : Record 370;VAR importerOptions@1000000006 : Integer;SourceRowsFilter@1000000002 : Text[50]); VAR keyFieldNo@1000000003 : Integer; Inserted@1000000007 : Boolean; BEGIN CLEAR(fieldMapping); fieldMapping.RESET; fieldMapping.DELETEALL; xlBuffer.RESET; xlBuffer.SETFILTER("Row No.",SourceRowsFilter); xlBuffer.SETRANGE(Underline,TRUE); IF xlBuffer.FIND('-') THEN REPEAT fieldMapping.INIT; fieldMapping := xlBuffer; IF xlBuffer.Formula2 <> '' THEN BEGIN EVALUATE(keyFieldNo, LeaveCharacters(xlBuffer.Formula2,'0123456789')); fieldMapping."Row No." := keyFieldNo + PrimaryKeyInfoBeginRow; END; fieldMapping.INSERT; UNTIL xlBuffer.NEXT = 0 ELSE BEGIN clearExcel; ERROR(Text010); END; END; LOCAL PROCEDURE generateWarning@1000000040(VAR fieldMapping@1000000000 : Record 370); VAR FieldName@1000000001 : Text[512]; FieldType@1000000002 : Text[512]; BEGIN IF warn THEN BEGIN fieldMapping.RESET; fieldMapping.SETFILTER(NumberFormat,'>%1',''); IF fieldMapping.FIND('-') THEN REPEAT FieldName := FieldName +fieldMapping.Formula4 +','; FieldType := FieldType +fieldMapping."Cell Value as Text" +','; UNTIL fieldMapping.NEXT =0; MESSAGE(Text011, FieldName, FieldType); END; END; PROCEDURE checkPrimaryKeyFieldNo@1000000030(tableNo@1000000000 : Integer;fieldNo@1000000001 : Integer) : Integer; VAR recRef@1000000005 : RecordRef; keyRef@1000000002 : KeyRef; fieldRef@1000000006 : FieldRef; keyCount@1000000003 : Integer; BEGIN recRef.OPEN(tableNo); keyRef := recRef.KEYINDEX(1); keyCount := keyRef.FIELDCOUNT; WHILE keyCount > 0 DO BEGIN fieldRef := keyRef.FIELDINDEX(keyCount); IF fieldRef.NUMBER = fieldNo THEN EXIT(keyCount); keyCount -= 1; END; EXIT(0); END; LOCAL PROCEDURE generatePrimaryKeyInfo@1000000017(tableNo@1000000002 : Integer;VAR primaryKeyFields@1000000000 : Record 370) : Integer; VAR recRef@1000000001 : RecordRef; keyRef@1000000007 : KeyRef; fieldRef@1000000011 : FieldRef; primaryKey@1000000003 : Text[252]; PKFieldCount@1000000004 : Integer; i@1000000005 : Integer; BEGIN recRef.OPEN(tableNo); primaryKey := recRef.GETPOSITION(FALSE); keyRef := recRef.KEYINDEX(1); PKFieldCount := keyRef.FIELDCOUNT; FOR i := 1 TO PKFieldCount DO BEGIN fieldRef := keyRef.FIELDINDEX(i); primaryKeyFields.INIT; primaryKeyFields."Row No." := i + PrimaryKeyInfoBeginRow; primaryKeyFields."Column No." := 0; primaryKeyFields.Comment := FORMAT(fieldRef.NUMBER,0,2); primaryKeyFields.NumberFormat := 'Required'; primaryKeyFields.Formula := fieldRef.NAME; primaryKeyFields.Formula2 := 'KeyField'+FORMAT(i,0,2); primaryKeyFields.Formula4 := FORMAT(fieldRef.TYPE); primaryKeyFields.INSERT; END; recRef.CLOSE; EXIT(PKFieldCount); END; LOCAL PROCEDURE generateFieldMapping@1000000035(tableNo@1000000005 : Integer;columnFilter@1000000012 : Text[1024];headerRow@1000000006 : Integer;ImporterOptions@1000000011 : Integer;VAR xlBuffer@1000000000 : Record 370) : Integer; VAR xlBuffer2@1000000002 : Record 370; field@1000000007 : Record 2000000041; fieldNo@1000000003 : Integer; KeyNo@1000000008 : Integer; fieldsFound@1000000001 : Integer; i@1000000010 : Integer; searchOption@1000000009 : 'FieldCaption,FieldName,FieldNo'; validateOption@1000000004 : 'All,None,FileDefined'; BEGIN searchOption := ROUND((ImporterOptions MOD 64)/8,1,'<'); validateOption := ROUND((ImporterOptions MOD 256)/32,1,'<'); xlBuffer.RESET; IF columnFilter <>'' THEN xlBuffer.SETFILTER("Column No.",columnFilter); xlBuffer.SETFILTER("Row No.", '%1..%2|%3',ConstantsAreaBeginRow,ConstantsAreaEndRow,headerRow) ; IF xlBuffer.FIND('-') THEN BEGIN REPEAT CASE searchOption OF searchOption::FieldCaption: fieldNo := findFieldNoByCaption(tableNo, xlBuffer."Cell Value as Text"); searchOption::FieldName: fieldNo := findFieldNoByName(tableNo, xlBuffer."Cell Value as Text"); searchOption::FieldNo: EVALUATE(fieldNo,xlBuffer."Cell Value as Text"); ELSE BEGIN clearExcel; ERROR(Text003, searchOption); END; END; KeyNo := 2*xlBuffer."Column No." +FieldMapBeginRow; IF fieldNo > 0 THEN BEGIN fieldsFound += 1; field.GET(tableNo,fieldNo); IF field.Class = field.Class::Normal THEN // field importable xlBuffer.NumberFormat := 'Importable' ELSE xlBuffer.NumberFormat := ''; CASE validateOption OF validateOption::All : xlBuffer.Bold := TRUE; validateOption::None : xlBuffer.Bold := FALSE; validateOption::FileDefined:; // BOLDed header inside Excel decides END; xlBuffer.Underline := TRUE; ; // Mapping found; xlBuffer.Comment := FORMAT(fieldNo,0,2); // maps to Field No xlBuffer.Formula := field.FieldName; // maps to Field Name i := checkPrimaryKeyFieldNo(tableNo,fieldNo); IF i > 0 THEN BEGIN KeyNo := PrimaryKeyInfoBeginRow +i; // moves keys to the PK area IF xlBuffer2.GET(KeyNo,0) THEN xlBuffer2.DELETE; xlBuffer.Formula2 := 'KeyField'+FORMAT(i,0,2) ; // field in primary key xlBuffer.NumberFormat := 'Required'; END; xlBuffer.Formula4 := FORMAT(field.Type); END ELSE BEGIN xlBuffer.Comment := ''; xlBuffer.Formula := ''; END; xlBuffer.MODIFY; xlBuffer.RENAME(KeyNo,xlBuffer."Column No."); UNTIL xlBuffer.NEXT = 0; END; xlBuffer.RESET; EXIT(fieldsFound); END; PROCEDURE renumberMappingData@1000000014(VAR xlBuffer@1000000000 : Record 370); VAR tempXlBuffer@1000000001 : TEMPORARY Record 370; span@1000000002 : Integer; i@1000000003 : Integer; BEGIN xlBuffer.RESET; xlBuffer.SETRANGE("Row No.", FieldMappingMinRange,FieldMappingMaxRange); xlBuffer.SETRANGE(Underline,TRUE); xlBuffer.SETRANGE("Column No.",0,256); span := xlBuffer.COUNT(); span := ROUND(ABS(FieldMappingMaxRange - FieldMappingMinRange)/span,1,'<'); i := FieldMappingMinRange; IF xlBuffer.FIND('-') THEN REPEAT tempXlBuffer := xlBuffer; tempXlBuffer."Row No." := i; i += span; IF NOT tempXlBuffer.INSERT THEN; UNTIL xlBuffer.NEXT = 0; xlBuffer.DELETEALL; IF tempXlBuffer.FIND('-') THEN REPEAT xlBuffer := tempXlBuffer; IF NOT xlBuffer.INSERT THEN; UNTIL tempXlBuffer.NEXT = 0; END; LOCAL PROCEDURE readHeader@1000000003(fileName@1000000002 : Text[512];sheetName@1000000001 : Text[50];headerRow@1000000007 : Integer;VAR tableNo@1000000000 : Integer;VAR xlBuffer@1000000003 : Record 370) : Integer; VAR HeaderRowFilter@1000000004 : Code[40]; newTableno@1000000005 : Integer; newHeaderRow@1000000006 : Integer; BEGIN xlBuffer.RESET; IF headerRow <= 0 THEN HeaderRowFilter := '-' ELSE HeaderRowFilter := '-' + FORMAT(headerRow,0,2)+'..'; headerRow := ReadSelectedSheetArea(xlBuffer,fileName,sheetName,HeaderRowFilter,''); IF tableNo > 0 THEN EXIT(headerRow); xlBuffer.SETRANGE("Row No.", headerRow); IF xlBuffer.FIND('-') THEN BEGIN IF readParameters(xlBuffer,newTableno,newHeaderRow) THEN BEGIN IF (tableNo<=0) AND (newTableno > 0) THEN tableNo := newTableno; IF newHeaderRow > 0 THEN headerRow := newHeaderRow-1; HeaderRowFilter := '-' + FORMAT(headerRow+1,0,2)+'..'; headerRow := ReadSelectedSheetArea(xlBuffer,fileName,sheetName,HeaderRowFilter,''); END; END; EXIT(headerRow); END; LOCAL PROCEDURE readParameters@1000000031(VAR xlBuffer@1000000000 : Record 370;VAR tableNo@1000000001 : Integer;VAR headerRow@1000000002 : Integer) paramOK : Boolean; VAR paramStr@1000000003 : Text[250]; paramVal@1000000004 : Text[250]; BEGIN xlBuffer.SETRANGE("Row No.", xlBuffer."Row No."); IF xlBuffer.FIND('-') THEN REPEAT paramStr := xlBuffer."Cell Value as Text"; IF retrieveParamVal(paramStr,'table:',paramVal) THEN BEGIN paramOK := paramOK OR EVALUATE(tableNo,paramVal); END; IF retrieveParamVal(paramStr,'header:',paramVal) THEN BEGIN paramOK := paramOK OR EVALUATE(headerRow,paramVal); END; UNTIL xlBuffer.NEXT =0; END; LOCAL PROCEDURE retrieveParamVal@1000000034(VAR paramStr@1000000000 : Text[512];paramDef@1000000001 : Text[30];VAR ParamVal@1000000002 : Text[250]) : Boolean; VAR i@1000000003 : Integer; l@1000000004 : Integer; paramBuf@1000000006 : Text[250]; BEGIN IF paramStr = '' THEN EXIT(FALSE); i := STRPOS(LOWERCASE(paramStr),LOWERCASE(paramDef)); IF i = 0 THEN EXIT(FALSE); l := STRLEN(paramDef); paramBuf := COPYSTR(paramStr,i); paramStr := COPYSTR(paramStr,1,i-1); i := STRPOS(paramBuf,';'); IF i = 0 THEN i := STRLEN(paramBuf)+1; ParamVal := COPYSTR(paramBuf,l+1,i-l-1); paramStr := paramStr + COPYSTR(paramBuf,i+1); EXIT(TRUE); END; EVENT XlApp@1000000014::NewWorkbook@1565(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::SheetSelectionChange@1558(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlApp@1000000014::SheetBeforeDoubleClick@1559(Sh@1000000002 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::SheetBeforeRightClick@1560(Sh@1000000002 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::SheetActivate@1561(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlApp@1000000014::SheetDeactivate@1562(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlApp@1000000014::SheetCalculate@1563(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlApp@1000000014::SheetChange@1564(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlApp@1000000014::WorkbookOpen@1567(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::WorkbookActivate@1568(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::WorkbookDeactivate@1569(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::WorkbookBeforeClose@1570(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::WorkbookBeforeSave@1571(Wb@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";SaveAsUI@1000000001 : Boolean;VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::WorkbookBeforePrint@1572(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::WorkbookNewSheet@1573(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlApp@1000000014::WorkbookAddinInstall@1574(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::WorkbookAddinUninstall@1575(Wb@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook"); BEGIN END; EVENT XlApp@1000000014::WindowResize@1554(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlApp@1000000014::WindowActivate@1556(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlApp@1000000014::WindowDeactivate@1557(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlApp@1000000014::SheetFollowHyperlink@1854(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00024431-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Hyperlink"); BEGIN END; EVENT XlApp@1000000014::SheetPivotTableUpdate@2157(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlApp@1000000014::WorkbookPivotTableCloseConnection@2160(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlApp@1000000014::WorkbookPivotTableOpenConnection@2161(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlApp@1000000014::WorkbookSync@2289(Wb@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";SyncEventType@1000000000 : Integer); BEGIN END; EVENT XlApp@1000000014::WorkbookBeforeXmlImport@2290(Wb@1000000004 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Map@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000002 : Text[1024];IsRefresh@1000000001 : Boolean;VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::WorkbookAfterXmlImport@2291(Wb@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";IsRefresh@1000000001 : Boolean;Result@1000000000 : Integer); BEGIN END; EVENT XlApp@1000000014::WorkbookBeforeXmlExport@2292(Wb@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000001 : Text[1024];VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlApp@1000000014::WorkbookAfterXmlExport@2293(Wb@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020819-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Workbook";Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000001 : Text[1024];Result@1000000000 : Integer); BEGIN END; EVENT XlWrkBk@1000000013::Open@1923(); BEGIN END; EVENT XlWrkBk@1000000013::Activate@304(); BEGIN END; EVENT XlWrkBk@1000000013::Deactivate@1530(); BEGIN END; EVENT XlWrkBk@1000000013::BeforeClose@1546(VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::BeforeSave@1547(SaveAsUI@1000000001 : Boolean;VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::BeforePrint@1549(VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::NewSheet@1550(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlWrkBk@1000000013::AddinInstall@1552(); BEGIN END; EVENT XlWrkBk@1000000013::AddinUninstall@1553(); BEGIN END; EVENT XlWrkBk@1000000013::WindowResize@1554(Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlWrkBk@1000000013::WindowActivate@1556(Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlWrkBk@1000000013::WindowDeactivate@1557(Wn@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020893-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Window"); BEGIN END; EVENT XlWrkBk@1000000013::SheetSelectionChange@1558(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlWrkBk@1000000013::SheetBeforeDoubleClick@1559(Sh@1000000002 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::SheetBeforeRightClick@1560(Sh@1000000002 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::SheetActivate@1561(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlWrkBk@1000000013::SheetDeactivate@1562(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlWrkBk@1000000013::SheetCalculate@1563(Sh@1000000000 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH"); BEGIN END; EVENT XlWrkBk@1000000013::SheetChange@1564(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlWrkBk@1000000013::SheetFollowHyperlink@1854(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00024431-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Hyperlink"); BEGIN END; EVENT XlWrkBk@1000000013::SheetPivotTableUpdate@2157(Sh@1000000001 : Automation ":{00020400-0000-0000-C000-000000000046}:''.IDISPATCH";Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlWrkBk@1000000013::PivotTableCloseConnection@2158(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlWrkBk@1000000013::PivotTableOpenConnection@2159(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; EVENT XlWrkBk@1000000013::Sync@2266(SyncEventType@1000000000 : Integer); BEGIN END; EVENT XlWrkBk@1000000013::BeforeXmlImport@2283(Map@1000000003 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000002 : Text[1024];IsRefresh@1000000001 : Boolean;VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::AfterXmlImport@2285(Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";IsRefresh@1000000001 : Boolean;Result@1000000000 : Integer); BEGIN END; EVENT XlWrkBk@1000000013::BeforeXmlExport@2287(Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000001 : Text[1024];VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkBk@1000000013::AfterXmlExport@2288(Map@1000000002 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{0002447B-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.XmlMap";Url@1000000001 : Text[1024];Result@1000000000 : Integer); BEGIN END; EVENT XlWrkSht@1000000015::SelectionChange@1543(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlWrkSht@1000000015::BeforeDoubleClick@1537(Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkSht@1000000015::BeforeRightClick@1534(Target@1000000001 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range";VAR Cancel@1000000000 : Boolean); BEGIN END; EVENT XlWrkSht@1000000015::Activate@304(); BEGIN END; EVENT XlWrkSht@1000000015::Deactivate@1530(); BEGIN END; EVENT XlWrkSht@1000000015::Calculate@279(); BEGIN END; EVENT XlWrkSht@1000000015::Change@1545(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020846-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Range"); BEGIN END; EVENT XlWrkSht@1000000015::FollowHyperlink@1470(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00024431-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.Hyperlink"); BEGIN END; EVENT XlWrkSht@1000000015::PivotTableUpdate@2156(Target@1000000000 : Automation "{00020813-0000-0000-C000-000000000046} 1.5:{00020872-0000-0000-C000-000000000046}:'Microsoft Excel 11.0 Object Library'.PivotTable"); BEGIN END; BEGIN { // // Universal Excel Importer // (c) 2006-2007 Slawek Guzek, sguzek@onet.pl // ImportData(tableNo, columnFilter, importOptions) : Integer tableNo - destination table number. If set to 0 Importer tries to read table no from Excel File, from any cell from first non-emty row of imported worksheet. If doesn't find 'table:' in a cell then asks user columnFilter - put here filter (in Navision syntax) which fields are allowed to import. Putting empty string here causes all fields are allowed. Importer don't allow to import data to flowfields or flowfilters, regardless of columnFilter value. When specifying filter remember to include primary key fields in it ! importOptions - tells Importer what to do with data: d1 d0 0 0 - illegal, Importer will change to 3 - Insert or Update 0 1 (importOptions=1) - insert new records 1 0 (importOptions=2) - update existing data 1 1 (importOptions=3) - insert new or update data when inserting new records insert will be done just after filling primary key fields, then fills the rest and launches MODIFY d2=1 (importOptions=4) - Delayed insert. when inserting Importer inserts records after filling all fields searching for fields in Excel header d5 d4 0 0 - search Excel headerby field Caption 0 1 (importOptions=16) - search Excel header by field Name 1 x (importOptions=32) - search Excel header by field No. use of VALIDATE trigger d7 d6 0 0 - VALIDATE all by default 0 1 (importOptions=64) - Don't VALIDATE all by default 1 x (importOptions=128) - VALIDATE according to header in Excel (Bold=VALIDATE) d8=1 (options=256) - don't use INSERT(True)/Modify(True) d10=1 (options=1024) - don't allow to change options user will not be allowed to change options (update,insert,OnInsert(True)) d11=1 (options=2048) - don't allow to change mapping user will not be allowed to add or change destination fields d12=1 (options=4096) - don't allow to change validation user will not be allowed to choose whether to VALIDATE destination field or not For example: if you want Importer to update only fields in destination table, and if you've put field numbers as header row in excel file use importOptions := 2+32 Usually put 0 here which mean Importer will try to match header assuming that it contains field captions IN CURRENT LANGUAGE, and insert new or update existing records in the destination table. ImportDataFromFile(VAR fileName, VAR sheetName,tableNo,headerRow,columnFilter,importOptions) fileName - put a TEXT VARIABLE here storing Excel file name to import. If variable is empty or file does not exist Importer asks for new file, and returns here selected filename. sheetName - put a TEXT VARIABLE here storing Excel worksheet to import. If variable is empty, or worksheet doesn't exist in Excel file, Importer allows user fo select one workheet among existing in file and returns user selection here tableNo - destination table number. Described in ImportData() function. headerRow - tells Importer where to find in Excel file row with field captions, names or numbers, or with parameters. The data to import is assumed to be in non empty rows below header. columnFilter - Described in ImportData() function. importOptions - Described in ImportData() function. Parameters settable inside Excel file table:number - sets destination table no header:number - sets row number from which Importer will start to search table header } END. } }